package com.adinnet.api.link.controller;


import com.adinnet.api.link.model.Link;
import com.adinnet.api.link.model.vo.LinkReq;
import com.adinnet.api.link.service.LinkService;
import com.adinnet.core.JsonResult;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

/**
 * <p>
 * 意向客户（被分享录入） 前端控制器
 * </p>
 *
 * @author chenjia
 * @since 2020-12-06
 */
@RestController
@RequestMapping("api/link")
public class LinkController {

    @Autowired
    private LinkService linkService;

    /**
     * 提交意向信息
     * @return
     */
    @PostMapping("submit")
    public JsonResult submit(@Valid @RequestBody LinkReq linkReq) {
        try {
            Link link = new Link();
            BeanUtils.copyProperties(linkReq,link);
            linkService.save(link);
            return JsonResult.ok();
        }catch (Exception e){
            return JsonResult.error("操作失败");
        }
    }
}
